home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / gui.cpp < prev    next >
C/C++ Source or Header  |  2005-04-27  |  43KB  |  1,002 lines

  1. /***************************************************************************
  2.                           gui.cpp  -  description
  3.                              -------------------
  4.     begin                : 06.08.02
  5.     copyright            : (C) 2002 by AndrΘ Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #include "gui.h"
  19. #include <wx/version.h>
  20.  
  21. #include "gui_failure_dlg.h"
  22.  
  23. using namespace std;
  24.  
  25. // Main Application
  26.  
  27. bool HighlightApp::OnInit()
  28. {
  29.    HighlightFrame *win = new HighlightFrame(HIGHLIGHT_VERSION2);   
  30.    
  31.    if (win->getFatalError())return FALSE;
  32.                                    
  33.    const wxCmdLineEntryDesc cmdLineDesc[] ={
  34.     { wxCMD_LINE_PARAM,  NULL, NULL, "input file", wxCMD_LINE_VAL_STRING,  
  35.       wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
  36.     { wxCMD_LINE_NONE }
  37.    };
  38.  
  39.    wxCmdLineParser parser(argc, argv);
  40.    parser.SetDesc(cmdLineDesc);
  41.    if (!parser.Parse() && parser.GetParamCount()){
  42.      wxArrayString inputFileList;
  43.      for (unsigned int i=0;i<parser.GetParamCount();i++){
  44.        inputFileList.Add(parser.GetParam(i));
  45.      } 
  46.      win->addInputFiles(inputFileList, "");                                            
  47.    }                                     
  48.                    
  49.    win->Centre();                                                     
  50.    win->Show(TRUE);
  51.    SetTopWindow(win);
  52.    win->showStartupTips();
  53.  
  54.    /* Do not return FALSE or the app will terminate immediately */
  55.    return TRUE;
  56. }
  57.  
  58. // Main Window
  59. HighlightFrame::HighlightFrame(const wxString &title)
  60.     : wxFrame((wxFrame *) NULL, -1, title, wxDefaultPosition, wxDefaultSize,
  61.                wxDEFAULT_FRAME_STYLE),
  62.      fatalError(false),
  63.      #ifdef WIN32
  64.       preferencesPath(string(::wxGetHomeDir().c_str())+"\\highlight.conf"),
  65.      #else
  66.       preferencesPath(string(::wxGetHomeDir().c_str())+"/.wxhighlight"),
  67.      #endif
  68.      styleOutFileName(NULL),
  69.      language("English"),
  70.      i18n(NULL),
  71.      prefConf(NULL)
  72. {    
  73.    prefConf=new ConfigurationReader(preferencesPath);
  74.    if (prefConf!=NULL&& prefConf->found()){
  75.       language=prefConf->getParameter("language");      
  76.    }
  77.    if (!loadLanguage(language)) {
  78.      fatalError=true; 
  79.    }  
  80.       
  81.    #ifdef WIN32
  82.     SetIcon(wxIcon(::wxGetCwd()+"\\WinHighlight.ico", wxBITMAP_TYPE_ICO));
  83.    #else
  84.     //SetIcon(wxIcon(::wxGetCwd()+"/WinHighlight.xpm", wxBITMAP_TYPE_ICO));
  85.    #endif
  86.     
  87.    outputFormats[0] = "HTML      ";
  88.    outputFormats[1] = "XHTML";
  89.    outputFormats[2] = "LaTeX";
  90.    outputFormats[3] = "TeX";
  91.    outputFormats[4] = "RTF";
  92.    outputFormats[5] = "XSL-FO"; 
  93.    outputFormats[6] = "XML";
  94.    
  95.    encodings[0] = "ISO-8859-1";
  96.    encodings[1] = "ISO-8859-2";
  97.    encodings[2] = "ISO-8859-3";
  98.    encodings[3] = "ISO-8859-4";
  99.    encodings[4] = "ISO-8859-5";
  100.    encodings[5] = "ISO-8859-6";
  101.    encodings[6] = "ISO-8859-7";
  102.    encodings[7] = "ISO-8859-8";
  103.    encodings[8] = "ISO-8859-9";
  104.    encodings[9] = "ISO-8859-10";
  105.    encodings[10] = "ISO-8859-11";
  106.    encodings[11] = "ISO-8859-13";
  107.    encodings[12] = "ISO-8859-14";
  108.    encodings[13] = "ISO-8859-15";
  109.    encodings[14] = "UFT-8";
  110.  
  111.    menu1 = new wxMenu(),
  112.    menu3 = new wxMenu();
  113.    menu2 = new wxMenu();
  114.     
  115.    MenuBar = new wxMenuBar();
  116.    // create a menu bar
  117.    menu1->Append(ID_MENU_OPENFILES,wxString(i18n->getCParameter ("m001")));
  118.    menu1->AppendSeparator();
  119.    menu1->Append(PROGRAM_QUIT,wxString(i18n->getCParameter ("m002")));
  120.    menu3->Append(ID_MENU_HELP, wxString(i18n->getCParameter("m003")));
  121.    menu3->Append(ID_MENU_TIPS, wxString(i18n->getCParameter("m009")));
  122.    menu3->AppendSeparator();
  123.    menu3->Append(ID_MENU_LICENSE, wxString(i18n->getCParameter("m004")));
  124.    menu3->Append(ID_MENU_CHANGELOG, wxString(i18n->getCParameter("m005")));
  125.    menu3->AppendSeparator();
  126.    menu3->Append(ID_MENU_ABOUT, wxString(i18n->getCParameter ("m006")));
  127.     
  128.    wxFileName i18nFileName;
  129.    wxSortedArrayString i18nFiles;
  130.    wxDir::GetAllFiles(dataDir.getI18nDir().c_str(), 
  131.                       &i18nFiles, "*.txt", wxDIR_FILES);
  132.    if ( i18nFiles.IsEmpty())
  133.    {
  134.        wxMessageBox(wxString("i18n folder not found. Check installation."),
  135.                     wxString("Error."), 
  136.                     wxICON_EXCLAMATION);
  137.        return;
  138.    }
  139.    // apart from English.txt, more translation files exist
  140.    bool translationsAvailable=i18nFiles.GetCount()>1; 
  141.    if (translationsAvailable){      
  142.      for (unsigned int i=0; i<i18nFiles.GetCount(); i++){ 
  143.        Connect(ID_MENU_LANGUAGE_DYN + i,  -1, wxEVT_COMMAND_MENU_SELECTED,
  144.                (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
  145.                &HighlightFrame::OnCheckLanguage);
  146.        i18nFileName.Assign(wxString(i18nFiles[i].c_str()));
  147.        menu2->AppendRadioItem(ID_MENU_LANGUAGE_DYN + i, i18nFileName.GetName());          
  148.      }
  149.      menu2->Check(menu2->FindItem(wxString(language.c_str())), true);
  150.   }      
  151.       
  152.    // Add it to the menu bar
  153.    MenuBar->Append(menu1, wxString(i18n->getCParameter ("m007")));
  154.    MenuBar->Append(menu2, wxString(i18n->getCParameter ("m008")));
  155.    MenuBar->Append(menu3, wxString(i18n->getCParameter ("m003")));   
  156.    SetMenuBar(MenuBar);
  157.    MenuBar->EnableTop(1, translationsAvailable);  
  158.    
  159.    panel =new wxPanel(this, ID_PANEL);
  160.    butSource = new wxButton(panel, ID_BUTTON_OPENFILES, 
  161.                             wxString(i18n->getCParameter ("l001")),
  162.                             wxDefaultPosition, wxSize(125, 25), 0 );
  163.  
  164.    listBox = new wxListBox(panel, ID_LISTBOX, wxDefaultPosition, 
  165.                            wxSize(200,390), 0, NULL, 
  166.                            wxLB_NEEDED_SB | wxLB_MULTIPLE | wxLB_HSCROLL);
  167.  
  168.    butRemoveSelection=new wxButton(panel, ID_BUTTON_REMOVE, 
  169.                                     wxString(i18n->getCParameter ("l033")),
  170.                                     wxDefaultPosition, wxSize(125, 25), 0 );
  171.                            
  172.    butClearList = new wxButton(panel, ID_BUTTON_CLEAR, 
  173.                                     wxString(i18n->getCParameter ("l003")),
  174.                                     wxDefaultPosition, wxSize(125, 25), 0 );
  175.  
  176.    // Spanish out directory label is very long, split in 2 lines
  177.    wxString outDirLbl;
  178.    outDirLbl.Printf(i18n->getCParameter ("l002"),"\n");
  179.    lblOutDir = new wxStaticText(panel, -1, outDirLbl);
  180.                               
  181.    outDir = new  wxTextCtrl(panel, ID_OUTDIRTEXT, "", wxDefaultPosition, 
  182.                            wxSize(175, 22));
  183.  
  184.    butOutDir = new wxButton( panel, ID_BUTTON_OUTDIR, "..." , wxDefaultPosition, 
  185.                              wxSize(20, 20), 0 );
  186.                            
  187.    writeToSourceDir= new wxCheckBox(panel, ID_WRITE_TO_SRCDIR, 
  188.                                  wxString( i18n->getCParameter ("l032") ));    
  189.  
  190.    outputFormat = new wxRadioBox(panel, ID_OUTPUTFORMAT, 
  191.                                  wxString(i18n->getCParameter("l004")),
  192.                                  wxDefaultPosition, wxDefaultSize, NUMBER_FORMATS,
  193.                                  outputFormats, 2,wxRA_SPECIFY_COLS);
  194.  
  195.    linenumbers = new wxCheckBox(panel, ID_INCLUDELINENUMBERS, 
  196.                                 wxString(i18n->getCParameter ("l013")));
  197.                                 
  198.    attachAnchors= new wxCheckBox(panel, ID_ATTACHANCHORS, 
  199.                                  wxString(i18n->getCParameter ("l006")));    
  200.                                  
  201.    lnFillZeroes = new wxCheckBox(panel, ID_FILL_ZEROES, 
  202.                                  wxString(i18n->getCParameter ("l031")));    
  203.  
  204.    wrapLines= new wxCheckBox(panel, ID_WRAP, 
  205.                                  wxString(i18n->getCParameter ("l027"))); 
  206.                                     
  207.    wrapLinesCautious= new wxCheckBox(panel, ID_WRAP_CAUTIOUS, 
  208.                                  wxString(i18n->getCParameter ("l028")));
  209.  
  210.    fragment = new wxCheckBox(panel, ID_FRAGMENT,
  211.                              wxString(i18n->getCParameter ("l014")));    
  212.                                                           
  213.    includeStyle = new wxCheckBox(panel, ID_INCLUDECSS, 
  214.                                wxString(i18n->getCParameter ("l005")));
  215.  
  216.    generateHtmlIndex=new wxCheckBox(panel, ID_GENERATEINDEX, 
  217.                                     wxString(i18n->getCParameter ("l008")));  
  218.                                                                       
  219.    replaceLatexQuotes=new wxCheckBox(panel, ID_REPLACE_QUOTES, 
  220.                                     wxString(i18n->getCParameter ("l029")));       
  221.  
  222.    lblColourTheme= new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l010")));    
  223.                                       
  224.    themeChoice=new wxChoice(panel, ID_THEMECHOICE, wxDefaultPosition,
  225.                             wxSize(100, 22));    
  226.  
  227.    reformatCode= new wxCheckBox(panel, ID_REFORMATCODE, 
  228.                                 wxString(i18n->getCParameter ("l007")),
  229.                                 wxDefaultPosition, wxSize(80, 22));
  230.  
  231.    formatChoice=new wxChoice(panel, ID_FORMATCHOICE, wxDefaultPosition,
  232.                              wxSize(55, 22));
  233.  
  234.    lblTabWidth=new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l030")));
  235.  
  236.    tabWidth= new wxSpinCtrl(panel, ID_TAB_WIDTH,"4", wxDefaultPosition, 
  237.                             wxSize(40, 22), wxSP_ARROW_KEYS, 0, 8 );
  238.                             
  239.    useEncoding= new wxCheckBox(panel, ID_USE_ENCODING, 
  240.                                 wxString(i18n->getCParameter ("l036")),
  241.                                 wxDefaultPosition, wxSize(80, 22));
  242.  
  243.    encodingChoice=new wxComboBox(panel, ID_ENCODING_LIST, "",wxDefaultPosition,
  244.                              wxSize(85, 22), NUMBER_ENCODINGS, encodings,
  245.                              wxCB_DROPDOWN | wxCB_SORT );
  246.    encodingChoice->SetSelection(0);                            
  247.  
  248.    wxString str;
  249.    str.Printf("%s %s", i18n->getCParameter ("l011"),
  250.                  ((styleOutFileName!=NULL)?(styleOutFileName->GetValue()).c_str():
  251.                   CSS_DEFAULT_NAME));
  252.                   
  253.    lblStyleIn= new wxStaticText(panel, -1,str);
  254.    styleInFileName = new wxTextCtrl(panel, ID_CSS_INFILE, "",
  255.                                   wxDefaultPosition,wxSize(120, 22)); 
  256.    butChooseStyleInfile = new wxButton( panel, ID_BUTTON_OPEN_CSS_INFILE, "...",
  257.                                      wxDefaultPosition, wxSize(20, 20), 0);
  258.                             
  259.    lblStyleOut= new wxStaticText(panel, -1, wxString(i18n->getCParameter ("l009")));
  260.  
  261.    styleOutFileName = new wxTextCtrl(panel, ID_CSS_OUTFILE, CSS_DEFAULT_NAME,
  262.                                    wxDefaultPosition,wxSize(150, 22));
  263.    
  264.    butStart = new wxButton(panel, ID_START, wxString(i18n->getCParameter("l015")), 
  265.                            wxDefaultPosition, wxSize(150, 30), 0 );
  266.    butStart->SetFont(wxFont(11, wxDEFAULT , wxNORMAL,wxBOLD));
  267.  
  268.    
  269.    progress= new wxGauge(panel, ID_PROGRESS, 100, wxDefaultPosition, 
  270.                          wxSize(150, 20),wxGA_SMOOTH );
  271.   
  272.   // Layout ***************************************************************
  273.   
  274.   wxBoxSizer *leftsizer = new wxBoxSizer( wxVERTICAL );
  275.   leftsizer->Add( butSource, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 ); 
  276.  
  277.   // create text ctrl with minimal size 100x60
  278.   leftsizer->Add(
  279.     listBox,
  280.     1,            // make vertically stretchable
  281.     wxGROW |    // make horizontally stretchable
  282.     wxALL,        //   and make border all around
  283.     10 );         // set border width to 10
  284.  
  285.   leftsizer->Add( butRemoveSelection, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  286.   leftsizer->Add(butClearList, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );        
  287.   leftsizer->Add(0,10);
  288.   
  289.    wxStaticBox *outDirBox= new wxStaticBox(panel, -1, "" );
  290.    wxStaticBoxSizer *outDirBoxSizer = new wxStaticBoxSizer( outDirBox, wxVERTICAL );    
  291.    wxBoxSizer* outDirSelSizer = new wxBoxSizer(wxHORIZONTAL);
  292.    outDirSelSizer->Add( outDir, 1, wxALIGN_CENTRE|wxALL , 5 );
  293.    outDirSelSizer->Add( butOutDir, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 0 );   
  294.    outDirBoxSizer->Add( lblOutDir, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2 );   
  295.    outDirBoxSizer->Add( outDirSelSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
  296.    outDirBoxSizer->Add( writeToSourceDir, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
  297.    leftsizer->Add(outDirBoxSizer,0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
  298.    
  299. //   wxBoxSizer *middlesizer = new wxBoxSizer( wxVERTICAL ); 
  300.    
  301.     wxBoxSizer *rightsizer = new wxBoxSizer( wxVERTICAL ); 
  302.    
  303.     rightsizer->Add(outputFormat, 0,  wxTOP | wxGROW| wxALIGN_LEFT, 0 );
  304.    
  305.     wxStaticBox *optBox= new wxStaticBox(panel, -1, "");
  306.     wxStaticBoxSizer *optBoxSizer = new wxStaticBoxSizer( optBox, wxVERTICAL );    
  307.     optBoxSizer->Add(linenumbers, 0, wxALIGN_LEFT, 5 );
  308.     optBoxSizer->Add( attachAnchors, 0,  wxTOP | wxALIGN_LEFT | wxLEFT, 5 ); 
  309.     optBoxSizer->Add( lnFillZeroes, 0,  wxTOP | wxALIGN_LEFT | wxLEFT, 5 );
  310. //    optBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition, 
  311.  //                     wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 10 );         
  312.     optBoxSizer->Add( wrapLines, 0,  wxTOP | wxALIGN_LEFT, 10 ); 
  313.     optBoxSizer->Add( wrapLinesCautious, 0,  wxTOP | wxALIGN_LEFT | wxLEFT, 5 ); 
  314.  //   optBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition, 
  315.   //                    wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 10 );         
  316.     optBoxSizer->Add( fragment, 0,  wxTOP | wxALIGN_LEFT, 10 ); 
  317.     optBoxSizer->Add( includeStyle, 0,  wxTOP | wxALIGN_LEFT, 5 ); 
  318.     optBoxSizer->Add( generateHtmlIndex, 0,  wxTOP | wxALIGN_LEFT, 5 ); 
  319.     optBoxSizer->Add( replaceLatexQuotes, 0,  wxTOP |wxBOTTOM| wxALIGN_LEFT, 5 ); 
  320.     rightsizer->Add(optBoxSizer,0, wxGROW|wxTOP, 5);
  321.     
  322.     wxStaticBox *choicesBox= new wxStaticBox(panel, -1, "");
  323.     wxStaticBoxSizer *choicesBoxSizer = new wxStaticBoxSizer( choicesBox, wxVERTICAL );  
  324.  
  325.     wxBoxSizer *themeSizer = new wxBoxSizer(wxHORIZONTAL );    
  326.     themeSizer->Add( lblColourTheme, 0,  wxTOP | wxALIGN_CENTER_VERTICAL , 3 ); 
  327.     themeSizer->Add(5, 0, 1);
  328.     themeSizer->Add( themeChoice, 0,  wxTOP , 5 ); 
  329.     choicesBoxSizer->Add( themeSizer, 0,  wxTOP| wxBOTTOM |wxGROW );
  330.     choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
  331.                           wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
  332.     wxBoxSizer *reformatSizer = new wxBoxSizer(wxHORIZONTAL );
  333.     reformatSizer->Add(reformatCode,0, wxTOP | wxALIGN_CENTER_VERTICAL, 5);
  334.     reformatSizer->Add(5, 0, 1);
  335.     reformatSizer->Add(formatChoice,0, wxTOP, 5);   
  336.     choicesBoxSizer->Add( reformatSizer, 0,  wxTOP |wxGROW, 5 );                                  
  337.     choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition, 
  338.                           wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
  339.     wxBoxSizer *tabSizer = new wxBoxSizer(wxHORIZONTAL );
  340.     tabSizer->Add(lblTabWidth, 0, wxTOP|wxALIGN_CENTER_VERTICAL , 5);
  341.     tabSizer->Add(5, 0, 1);
  342.     tabSizer->Add(tabWidth, 0, wxTOP, 3);
  343.     choicesBoxSizer->Add( tabSizer, 0, wxTOP| wxBOTTOM| wxGROW, 5 );  
  344.     choicesBoxSizer->Add( new wxStaticLine(panel, -1, wxDefaultPosition,
  345.                           wxDefaultSize, wxLI_HORIZONTAL ), 0, wxGROW|wxTOP|wxLEFT|wxRIGHT, 5 );
  346.     wxBoxSizer *encodingSizer = new wxBoxSizer(wxHORIZONTAL );
  347.     encodingSizer->Add(useEncoding,0, wxTOP | wxALIGN_CENTER_VERTICAL, 5);
  348.     encodingSizer->Add(5, 0, 1);
  349.     encodingSizer->Add(encodingChoice,0, wxTOP, 5);   
  350.     choicesBoxSizer->Add( encodingSizer, 0,  wxTOP |wxGROW, 5 );                                  
  351.                           
  352.     rightsizer->Add(choicesBoxSizer,0, wxGROW|wxTOP, 5);
  353.     
  354.     wxStaticBox *styleOptBox= new wxStaticBox(panel, -1, "");
  355.     wxStaticBoxSizer *styleOptBoxBoxSizer = new wxStaticBoxSizer( styleOptBox, wxVERTICAL );        
  356.     styleOptBoxBoxSizer->Add( lblStyleOut, 0 ); 
  357.     styleOptBoxBoxSizer->Add( styleOutFileName, 0,  wxTOP | wxGROW | wxALIGN_LEFT, 5 ); 
  358.     styleOptBoxBoxSizer->Add( lblStyleIn, 0,  wxTOP | wxALIGN_LEFT, 10 );     
  359.     wxBoxSizer *styleInSizer = new wxBoxSizer(wxHORIZONTAL );    
  360.     styleInSizer->Add( styleInFileName, 1,  wxTOP | wxGROW | wxALIGN_LEFT, 5 ); 
  361.     styleInSizer->Add( butChooseStyleInfile, 0,  wxBOTTOM|wxTOP| wxLEFT| wxALIGN_CENTER_VERTICAL, 5 );     
  362.     styleOptBoxBoxSizer->Add( styleInSizer, 0, wxBOTTOM|wxGROW, 5);   
  363.     rightsizer->Add(styleOptBoxBoxSizer,0, wxGROW|wxTOP, 5);     
  364.  
  365.     rightsizer->Add(0, 20, 1);
  366.     rightsizer->Add( butStart, 0,  wxTOP | wxGROW, 10 ); 
  367.     rightsizer->Add( progress, 0,  wxTOP | wxBOTTOM| wxGROW | wxALIGN_BOTTOM, 10 );
  368.  
  369.     wxBoxSizer *panelsizer = new wxBoxSizer( wxHORIZONTAL );
  370.    
  371.     panelsizer->Add(leftsizer, 1, wxGROW|wxRIGHT, 20);
  372.     panelsizer->Add(rightsizer, 0,wxGROW|wxRIGHT, 10);
  373.  
  374.    panelsizer->SetSizeHints( this );   // set size hints to honour minimum size
  375.    panel->SetSizer( panelsizer );      // use the sizer for layout
  376.  
  377.     // Create the status bar
  378.    CreateStatusBar(2);
  379.    SetStatusText(wxString(i18n->getCParameter("l024")),1);
  380.  
  381.  
  382.    fillChoiceCtrl(themeChoice, wxString(dataDir.getThemeDir().c_str()), "*.style");
  383.    fillChoiceCtrl(formatChoice, wxString(dataDir.getIndentSchemesDir().c_str()), "*.indent");
  384.   
  385.    assignToolTip(butSource,"t001"); 
  386.    assignToolTip(butOutDir,"t002");
  387.    assignToolTip(butChooseStyleInfile,"t003");
  388.    assignToolTip(butClearList,"t004");
  389.    assignToolTip(styleOutFileName,"t005"); 
  390.    assignToolTip(styleInFileName,"t006");
  391.    assignToolTip(outDir,"t007");
  392.    assignToolTip(includeStyle,"t008");
  393.    assignToolTip(fragment,"t009"); 
  394.    assignToolTip(linenumbers,"t010");
  395.    assignToolTip(attachAnchors,"t011");
  396.    assignToolTip(reformatCode,"t012");
  397.    assignToolTip(outputFormat,"t013"); 
  398.    assignToolTip(butStart,"t014");
  399.    assignToolTip(generateHtmlIndex,"t015");
  400.    assignToolTip(formatChoice,"t016");
  401.    assignToolTip(themeChoice,"t017"); 
  402.    assignToolTip(wrapLines,"t018");
  403.    assignToolTip(wrapLinesCautious,"t019");
  404.    assignToolTip(replaceLatexQuotes,"t020");
  405.    assignToolTip(tabWidth,"t021"); 
  406.    assignToolTip(lnFillZeroes,"t022");
  407.    assignToolTip(writeToSourceDir,"t023");
  408.    assignToolTip(butRemoveSelection,"t024");
  409.    assignToolTip(useEncoding,"t025");
  410.        
  411.    applyPreferences();
  412.    plausiChecks();
  413.    
  414.    fileFilter=wxString(readFile(dataDir.getExtDir()+"fileopenfilter.conf").c_str());
  415.    if (fileFilter.empty()){
  416.      fileFilter="All source code (*.*)|*.*|";
  417.    }  
  418.    
  419.    bool extensionsFound=loadFileExtensions();
  420.    if (!extensionsFound){
  421.      wxMessageBox(wxString(i18n->getCParameter ("e008")),
  422.                            wxString(i18n->getCParameter ("l025")), 
  423.                            wxICON_EXCLAMATION);
  424.    }
  425.    
  426.    // initialize drag and drop
  427.    listBox->SetDropTarget (new DropFiles (this));
  428.  
  429. }
  430.  
  431. void HighlightFrame::assignToolTip(wxWindow* widget, const char* tipName){
  432.    widget ->SetToolTip(wxString(i18n->getCParameter(tipName)));
  433. }
  434.  
  435. void HighlightFrame::fillChoiceCtrl(wxChoice* choice, const wxString &dir, const wxString &ext){     
  436.    if (!choice) return;
  437.    
  438.    wxFileName fName;
  439.    wxSortedArrayString files;
  440.    wxDir::GetAllFiles(dir, &files, ext);
  441.    for (unsigned int i=0;i<files.GetCount(); i++){ 
  442.      fName.Assign(files[i]);
  443.      choice->Append(fName.GetName());
  444.    }                                                                                    
  445.    choice->SetSelection(0);
  446. }
  447.  
  448. void HighlightFrame::showStartupTips(bool forceTips){
  449.   if (showTips || forceTips ){
  450.      wxString tipsFile;
  451.      const char *i18nPath = dataDir.getI18nDir().c_str();
  452.      tipsFile.Printf("%s%s.tips",i18nPath, language.c_str());
  453.      if (!::wxFileExists(tipsFile)){
  454.        tipsFile.Printf("%s%s.tips", i18nPath, "English");
  455.      }    
  456.      wxTipProvider *tipProvider = wxCreateFileTipProvider(tipsFile, lastTip);
  457.      showTips=wxShowTip(this, tipProvider,showTips);
  458.      lastTip=tipProvider->GetCurrentTip();
  459.      delete tipProvider;     
  460.   } 
  461. }
  462.  
  463. void HighlightFrame::OnTips(wxCommandEvent & WXUNUSED(event)){
  464.   showStartupTips(true);
  465. }
  466.  
  467. bool HighlightFrame::loadLanguage(const string &newLanguage){
  468.     wxString i18nPath; 
  469.     i18nPath.Printf("%s%s.txt",dataDir.getI18nDir().c_str(), newLanguage.c_str() );
  470.     delete i18n;
  471.     i18n= new ConfigurationReader(i18nPath.c_str());
  472.     if (!i18n->found()){
  473.       wxString errMsg;
  474.       errMsg.Printf("Could not load GUI language file (%s). Check installation.",
  475.                     i18nPath.c_str());
  476.       wxMessageBox(errMsg, "Highlight Fatal Error", wxICON_EXCLAMATION);
  477.       return false;
  478.     }
  479.     language=newLanguage;
  480.     return true;
  481. }
  482.  
  483. string HighlightFrame::readFile(const string &path, bool keepNewLine){
  484.   ifstream in (path.c_str());
  485.   string content;
  486.   if (in) {
  487.     string line;
  488.     unsigned int firstNonWs;
  489.     while (getline(in, line)) {
  490.       firstNonWs = line.find_first_not_of("\t ");
  491.       if ((firstNonWs!=string::npos) && (line[firstNonWs]!='#')){
  492.          content +=line;
  493.          if (keepNewLine) {
  494.            content +="\n";
  495.          }           
  496.       }
  497.    }
  498.  }
  499.  return content;  
  500. }
  501.  
  502. bool HighlightFrame::loadFileExtensions(){
  503.   ConfigurationReader extensionsConfig(dataDir.getExtDir() + "extensions.conf");  
  504.   if (extensionsConfig.found())
  505.   {
  506.     stringstream values;
  507.     string paramName, paramVal;
  508.     for (unsigned int i=0;i<extensionsConfig.getParameterNames().size();i++)    
  509.      {
  510.        paramName = extensionsConfig.getParameterNames()[i];
  511.        values.str(extensionsConfig.getParameter(paramName)) ;        
  512.        while (values >> paramVal) {         
  513.           extensions[ paramVal ] = paramName;     
  514.        }
  515.        values.clear();
  516.       }
  517.       return true;
  518.     }
  519.   return false;
  520. }
  521.  
  522. void HighlightFrame::OnClickButtonSource(wxCommandEvent & WXUNUSED(event))
  523. {
  524.   wxArrayString chosenFiles;
  525.   wxFileDialog openFiles(this,wxString(i18n->getCParameter("l018")), 
  526.                          openFileDir,  "",
  527.                          fileFilter,
  528.                          wxMULTIPLE | wxFILE_MUST_EXIST);
  529.   openFiles.ShowModal();  
  530.   openFiles.GetFilenames(chosenFiles);
  531.   openFileDir=openFiles.GetDirectory();
  532.   if (openFileDir[openFileDir.length()-1] != Platform::pathSeparator ) {
  533.     openFileDir += Platform::pathSeparator;
  534.   }
  535.   if (outDir->GetValue().IsEmpty()){
  536.       outDir->SetValue(openFileDir);  
  537.   }
  538.   addInputFiles(chosenFiles, openFileDir);
  539. }
  540.  
  541. void HighlightFrame::addInputFiles(const wxArrayString& inputFiles, 
  542.                                const wxString &prefix){
  543.   wxString absInFilePath;
  544.   for (unsigned int i=0; i< inputFiles.GetCount(); i++){
  545.      absInFilePath.Printf("%s%s", prefix.c_str(), inputFiles[i].GetData());
  546.      if (listBox->FindString(absInFilePath) == -1) {
  547.        listBox->Append(absInFilePath);
  548.      }
  549.   }
  550. }
  551.  
  552. void HighlightFrame::OnClickButtonTargetDir(wxCommandEvent & WXUNUSED(event))
  553. {
  554.   wxDirDialog targetDir(this,wxString(i18n->getCParameter("l002")), "");
  555.   targetDir.ShowModal();
  556.   outDir->SetValue(targetDir.GetPath());
  557. }
  558.  
  559. void HighlightFrame::OnClickButtonClear(wxCommandEvent & WXUNUSED(event)){
  560.   listBox->Clear();
  561. }
  562.  
  563. void HighlightFrame::OnClickButtonRemSelection(wxCommandEvent &event){
  564.   wxArrayInt selectedItems;     
  565.   listBox->GetSelections (selectedItems);
  566.   size_t cnt = selectedItems.GetCount();
  567.   if (cnt){
  568.     for (size_t i=0;i<cnt;i++){
  569.       listBox->Delete(selectedItems[i]-i);
  570.     }
  571.   }
  572. }
  573.  
  574.  
  575. void HighlightFrame::OnHelp(wxCommandEvent & WXUNUSED(event)){
  576.    showTextFile("README.txt");
  577. }
  578. void HighlightFrame::OnLicense(wxCommandEvent & WXUNUSED(event)){
  579.    showTextFile("COPYING.txt");
  580. }
  581. void HighlightFrame::OnChangelog(wxCommandEvent & WXUNUSED(event)){
  582.    showTextFile("ChangeLog.txt");
  583. }
  584.  
  585. void HighlightFrame::OnCheckLanguage(wxCommandEvent & event){
  586.   bool langFound=loadLanguage(menu2->GetLabel( event.GetId()).c_str());
  587.   if (langFound){
  588.     wxMessageBox(wxString(i18n->getCParameter("l026")),
  589.                  wxString(i18n->getCParameter("l019")), 
  590.                  wxICON_INFORMATION);
  591.   }  
  592. }
  593.  
  594. void HighlightFrame::OnAbout(wxCommandEvent & WXUNUSED(event)){
  595.    string translatorsList=readFile(dataDir.getI18nDir()+"Translators.list", true);
  596.    if (translatorsList.empty()){
  597.      translatorsList="Error: File "+dataDir.getI18nDir()+
  598.                      "Translators.list not found.\n";
  599.    }
  600.    formatMsg.Printf(MSG_INFO_TXT, HIGHLIGHT_VERSION, wxMAJOR_VERSION, 
  601.                     wxMINOR_VERSION, wxRELEASE_NUMBER,
  602.                     translatorsList.c_str(),HIGHLIGHT_URL);
  603.    wxMessageBox(formatMsg,wxString(i18n->getCParameter("l019")), 
  604.                 wxICON_INFORMATION);
  605. }
  606.  
  607. void HighlightFrame::showTextFile(const wxString &file){
  608.    wxString cmd="notepad ";
  609.    cmd.Printf("notepad %s%c%s",dataDir.getDir().c_str(),Platform::pathSeparator,file.c_str());
  610.  
  611.    long result = wxExecute(cmd, true);
  612.    if (result == -1){
  613.       wxMessageBox(wxString(i18n->getCParameter("e001")),
  614.                    wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
  615.    }
  616. }
  617.  
  618. void HighlightFrame::plausiChecks(){ 
  619.  
  620.   bool webOutput=(outputFormat->GetSelection()<2);
  621.   bool extStyleEnabled=(outputFormat->GetSelection()<4);
  622.   bool write2outdir = !writeToSourceDir ->GetValue();
  623.   includeStyle->Enable(extStyleEnabled || !write2outdir);
  624.   styleOutFileName->Enable(extStyleEnabled && !includeStyle->GetValue()&&write2outdir);
  625.   styleInFileName->Enable(extStyleEnabled);
  626.   lblStyleOut->Enable(extStyleEnabled&&!includeStyle->GetValue()&&write2outdir);
  627.   lblStyleIn->Enable(extStyleEnabled);
  628.   butChooseStyleInfile->Enable(extStyleEnabled);  
  629.   attachAnchors->Enable(linenumbers->GetValue() && webOutput);
  630.   lnFillZeroes->Enable(linenumbers->GetValue());
  631.   formatChoice->Enable(reformatCode->GetValue());
  632.   wrapLinesCautious->Enable(wrapLines->GetValue());  
  633.   replaceLatexQuotes->Enable(outputFormat->GetSelection()==2 
  634.                              && fragment->GetValue());  
  635.   lblTabWidth->Enable(!reformatCode->GetValue());
  636.   tabWidth->Enable(!reformatCode->GetValue());
  637.   generateHtmlIndex->Enable(webOutput && write2outdir);
  638.  
  639.   lblOutDir ->Enable(write2outdir);
  640.   butOutDir->Enable(write2outdir);
  641.   outDir->Enable(write2outdir);
  642.   if (!write2outdir)  includeStyle->SetValue(extStyleEnabled);
  643.     
  644.   if (tabWidth->GetValue()<0)                             
  645.     tabWidth->SetValue(0);
  646.   else if (tabWidth->GetValue()>8)                             
  647.     tabWidth->SetValue(8); 
  648.   
  649.   if (extStyleEnabled){
  650.     checkStyleReferences(styleOutFileName, webOutput); 
  651.     checkStyleReferences(styleInFileName, webOutput);
  652.   }
  653.   bool enableEncoding =    outputFormat->GetSelection()<2 
  654.                         || outputFormat->GetSelection()>4;
  655.   useEncoding->Enable(enableEncoding);
  656.   encodingChoice->Enable(enableEncoding && useEncoding->GetValue());
  657.   SetStyleInLabel();
  658. }
  659.  
  660. void HighlightFrame::checkStyleReferences(wxTextCtrl *styleCtrl, bool webOutput){
  661.     wxString stylePath = styleCtrl->GetValue(); 
  662.     if (stylePath.Matches( (webOutput)? "*.sty" : "*.css")) {
  663.       stylePath.Printf((webOutput)?"%s.css":"%s.sty", 
  664.                        stylePath.Mid(0, stylePath.Length()-4).c_str());    
  665.       styleCtrl->SetValue (stylePath);
  666.     }
  667. }
  668.  
  669. void HighlightFrame::OnStyleOutfileChanged(wxCommandEvent & WXUNUSED(event)){
  670.     SetStyleInLabel();
  671. }
  672.  
  673. void HighlightFrame::SetStyleInLabel(){
  674.     wxString str;
  675.     str.Printf("%s %s",i18n->getCParameter ("l011"),
  676.               ( (includeStyle->GetValue()) ? i18n->getCParameter ("l035"):
  677.                   ((styleOutFileName!=NULL)?(styleOutFileName->GetValue()).c_str():
  678.                                            CSS_DEFAULT_NAME )));
  679.     lblStyleIn->SetLabel(str); 
  680. }    
  681.  
  682. void HighlightFrame::OnClickButtonOpenStyleFile(wxCommandEvent & WXUNUSED(event))
  683. {
  684.   wxArrayString chosenFiles;
  685.   wxFileDialog openFiles(this,i18n->getCParameter ("l018"),"",  "",
  686.                          "CSS input file (*.css)|*.css|",
  687.                          wxMULTIPLE|wxFILE_MUST_EXIST );
  688.   openFiles.ShowModal();
  689.   wxString chosenFile=openFiles.GetDirectory();
  690.   chosenFile.Append(Platform::pathSeparator);
  691.   chosenFile.Append(openFiles.GetFilename());
  692.   styleInFileName->SetValue(chosenFile);
  693. }
  694.  
  695. void HighlightFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
  696. {     
  697.   if (!writePreferences()) {
  698.     wxMessageBox (wxString(i18n->getCParameter ("e006")),
  699.                   wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
  700.   }
  701.   if (i18n) delete i18n;
  702.   if (prefConf) delete prefConf;
  703.     
  704.   this->Destroy();
  705. }
  706.  
  707. bool HighlightFrame::writePreferences(){
  708.   if (!fatalError) {
  709.     ofstream pref (preferencesPath.c_str());
  710.     if (!pref.fail()){
  711.       pref << "# WinHighlight Preferences - Please do not edit unless you know "
  712.            << "what you're doing";
  713.       pref << "\n$outdir="<<outDir->GetValue().c_str();
  714.       pref << "\n$outputformat="<< outputFormat->GetSelection() ;
  715.       pref << "\n$outcssfile="<<(styleOutFileName->GetValue()).GetData();
  716.       pref << "\n$incssfile="<<(styleInFileName->GetValue()).GetData();
  717.       pref << "\n$themechoice="<<themeChoice->GetSelection();
  718.       pref << "\n$openfiledir="<<openFileDir.c_str();
  719.       pref << "\n$includecss="<<includeStyle->GetValue();
  720.       pref << "\n$fragment="<<fragment->GetValue();
  721.       pref << "\n$linenumbers="<<linenumbers->GetValue();
  722.       pref << "\n$attachanchors="<<attachAnchors->GetValue();
  723.       pref << "\n$reformatcode="<<reformatCode->GetValue();
  724.       pref << "\n$formatchoice="<<formatChoice->GetSelection();
  725.       pref << "\n$encodingval="<<encodingChoice->GetValue();
  726.       pref << "\n$useencoding="<<useEncoding->GetValue();
  727.       pref << "\n$generatehtmlindex="<<generateHtmlIndex->GetValue();
  728.       pref << "\n$wrap="<<wrapLines->GetValue();
  729.       pref << "\n$wrapsimple="<<wrapLinesCautious->GetValue();     
  730.       pref << "\n$replacequotes="<<replaceLatexQuotes->GetValue();     
  731.       pref << "\n$language="<<language;
  732.       pref << "\n$showtips="<<showTips;
  733.       pref << "\n$lasttip="<<lastTip;
  734.       pref << "\n$tabwidth="<<tabWidth->GetValue();
  735.       pref << "\n$fillzeroes="<<lnFillZeroes->GetValue();
  736.       pref << "\n$write2src="<<writeToSourceDir->GetValue();
  737.      
  738.       pref.close();
  739.       return true;
  740.     }
  741.   } 
  742.   return fatalError;  
  743. }
  744.  
  745. bool HighlightFrame::applyPreferences(){
  746.     string trueStr("1");
  747.     if (prefConf != NULL && prefConf->found()){
  748.       outDir->SetValue(prefConf->getParameter("outdir").c_str());
  749.       outputFormat->SetSelection(StringTools::str2int(prefConf->
  750.                                  getParameter("outputformat")));      
  751.       themeChoice->SetSelection(StringTools::str2int(prefConf->
  752.                                 getParameter("themechoice")));
  753.       openFileDir=prefConf->getParameter("openfiledir").c_str();
  754.       includeStyle->SetValue(prefConf->getParameter("includecss")==trueStr);
  755.       fragment->SetValue(prefConf->getParameter("fragment")==trueStr);
  756.       linenumbers->SetValue(prefConf->getParameter("linenumbers")==trueStr);
  757.       attachAnchors->SetValue(prefConf->getParameter("attachanchors")==trueStr);
  758.       reformatCode->SetValue(prefConf->getParameter("reformatcode")==trueStr);
  759.       generateHtmlIndex->SetValue(prefConf->
  760.                                   getParameter("generatehtmlindex")==trueStr);
  761.       wrapLines->SetValue(prefConf->getParameter("wrap")==trueStr);
  762.       wrapLinesCautious->SetValue(prefConf->
  763.                                   getParameter("wrapsimple")==trueStr);                                                                    
  764.       replaceLatexQuotes->SetValue(prefConf->
  765.                                   getParameter("replacequotes")==trueStr);                                                                                                      
  766.       formatChoice->SetSelection(StringTools::str2int(prefConf->
  767.                                  getParameter("formatchoice")));
  768.       language=prefConf->getParameter("language");      
  769.       showTips=prefConf->getParameter("showtips")==trueStr;
  770.       lastTip= StringTools::str2int( prefConf->getParameter("lasttip"));    
  771.       tabWidth->SetValue(wxString(prefConf->getCParameter("tabwidth"))); 
  772.       lnFillZeroes->SetValue(prefConf->getParameter("fillzeroes")==trueStr);
  773.       styleOutFileName->SetValue(prefConf->getParameter("outcssfile").c_str());
  774.       styleInFileName->SetValue(prefConf->getParameter("incssfile").c_str());      
  775.       writeToSourceDir->SetValue(prefConf->getParameter("write2src")==trueStr);
  776.  
  777.       encodingChoice->SetValue(wxString(prefConf->getCParameter("encodingval")));
  778.       useEncoding->SetValue(prefConf->getParameter("useencoding")==trueStr);
  779.  
  780.       SetStyleInLabel();
  781.       return true;
  782.     }
  783.     return false;
  784. }
  785.  
  786. highlight::OutputType HighlightFrame::getOutputType(){
  787.     switch (outputFormat->GetSelection()){
  788.      case 0: return highlight::HTML;
  789.      case 1: return highlight::XHTML;
  790.      case 2: return highlight::LATEX;
  791.      case 3: return highlight::TEX;
  792.      case 4: return highlight::RTF;
  793.      case 5: return highlight::XSLFO;
  794.      case 6: return highlight::XML;
  795.     }
  796.     return highlight::HTML;    
  797. }    
  798.  
  799. void HighlightFrame::OnClickButtonStart(wxCommandEvent & WXUNUSED(event)){
  800.  
  801.     if (!listBox->GetCount())
  802.         return;
  803.  
  804.     if (!writeToSourceDir->GetValue() && !wxDir::Exists(outDir->GetValue()))
  805.     {
  806.       wxMessageBox(wxString(i18n->getCParameter("l020")),
  807.                    wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
  808.       outDir->SetFocus();
  809.       return;
  810.     }
  811.     if (outputFormat->GetSelection()<2 && (includeStyle->GetValue()==false)
  812.         &&(styleOutFileName->GetValue().IsEmpty()))
  813.     {
  814.       wxMessageBox(wxString(i18n->getCParameter("l021")),
  815.                    wxString(i18n->getCParameter("l025")), wxICON_EXCLAMATION);
  816.       styleOutFileName->SetFocus();
  817.       return;
  818.     }
  819.     
  820.     wxStopWatch stopWatch;
  821.             
  822.     string outPath((outDir->GetValue()).c_str());
  823.     if (outPath[outPath.length()-1] != Platform::pathSeparator ) {
  824.       outPath +=Platform::pathSeparator;
  825.     }
  826.     wxString stylePath;
  827.     stylePath.Printf("%s%s.style", dataDir.getThemeDir().c_str(), 
  828.                                    themeChoice->GetStringSelection().c_str());
  829.     
  830.     highlight::CodeGenerator *generator =
  831.       highlight::CodeGenerator::getInstance(getOutputType(),
  832.                                             stylePath.c_str(),
  833.                                             (styleInFileName->GetValue()).GetData(),
  834.                                             (styleOutFileName->GetValue()).GetData(),
  835.                                             (encodingChoice->GetValue()).GetData(),
  836.                                             includeStyle->GetValue(),
  837.                                             attachAnchors->GetValue(),
  838.                                             replaceLatexQuotes->GetValue(),
  839.                                             true,
  840.                                             tabWidth->GetValue(),
  841.                                             getWrappingStyle(),
  842.                                             linenumbers->GetValue(),
  843.                                             lnFillZeroes->GetValue(),
  844.                                             fragment->GetValue(),
  845.                                             !useEncoding->GetValue());
  846.         
  847.     if (reformatCode->GetValue()){
  848.        wxString indentSchemePath;
  849.       indentSchemePath.Printf("%s%s.indent", dataDir.getIndentSchemesDir().c_str(), 
  850.                                    formatChoice->GetStringSelection().c_str());
  851.       generator->initIndentationScheme(indentSchemePath.c_str());
  852.     }    
  853.         
  854.     string outfileName;
  855.     string langDefPath;
  856.     string suffix;
  857.     int fileCount=0;
  858.     highlight::ParseError error;
  859.     highlight::LoadResult loadRes;
  860.     wxArrayString reformatFailures, outputFailures, inputFailures;
  861.     wxString currentInputFile;
  862.  
  863.     SetStatusText(wxString(i18n->getCParameter ("l017")),1);
  864.     wxBeginBusyCursor();
  865.  
  866.     while( fileCount < listBox->GetCount())
  867.     {
  868.        currentInputFile= listBox->GetString(fileCount); 
  869.        // dekl. aus schleife gezogen    
  870.        suffix = getFileType(getFileSuffix(currentInputFile.c_str()));       
  871.        langDefPath = dataDir.getLangDefDir() + suffix + ".lang";
  872.        loadRes= generator->initLanguage(langDefPath);
  873.  
  874.        if (loadRes==highlight::LOAD_FAILED) {
  875.           formatMsg.Printf(wxString(i18n->getCParameter ("e002")), 
  876.                                     suffix.c_str());
  877.           wxMessageBox(formatMsg, wxString(i18n->getCParameter("l025")), 
  878.                        wxICON_EXCLAMATION);
  879.        } else {
  880.               
  881.           if (reformatCode->GetValue()&& !generator->formattingIsPossible()){             
  882.              reformatFailures.Add(currentInputFile);
  883.           }
  884.            
  885.           if (writeToSourceDir->GetValue()) { //write output to source directories?
  886.             outfileName = string(currentInputFile.c_str());
  887.           } else {
  888.             outfileName = outPath;
  889.             outfileName += wxFileName(currentInputFile).GetFullName().c_str();
  890.           }
  891.           outfileName += getOutFileSuffix();
  892.           error = generator->printOutput(currentInputFile.c_str(), 
  893.                                          outfileName.c_str() );
  894.                                    
  895.           if (error != highlight::PARSE_OK){
  896.             stopWatch.Pause();
  897.             if (error == highlight::BAD_INPUT) {
  898.               inputFailures.Add(currentInputFile);
  899.             }
  900.             else {
  901.               outputFailures.Add(wxString(outfileName.c_str()));
  902.             }
  903.             stopWatch.Resume();
  904.           }
  905.           progress->SetValue(100 * fileCount / listBox->GetCount());
  906.        }
  907.        ++fileCount;
  908.    }
  909.    
  910.    // print external style definition file
  911.    if (!includeStyle->GetValue()){               
  912.       string css_name = (styleOutFileName->GetValue()).GetData();
  913.       string csspath = outPath;
  914.       unsigned int pos = css_name.find_last_of('\\');
  915.       if (pos == string::npos) {
  916.          pos = css_name.find_last_of('/');
  917.       }
  918.       if ((pos != string::npos) && (pos < css_name.length())) {
  919.          csspath += css_name.substr(pos+1, css_name.length());
  920.       } else {
  921.          csspath += css_name;
  922.       }                                                                 
  923.       bool styleFileOK=generator -> printExternalStyle(csspath);
  924.       if (!styleFileOK) {
  925.          formatMsg.Printf(wxString(i18n->getCParameter("e004")), 
  926.                           styleInFileName->GetValue().GetData());
  927.          wxMessageBox(formatMsg, wxString(i18n->getCParameter("l025")), 
  928.                       wxICON_EXCLAMATION);
  929.       }
  930.     }
  931.     
  932.     // print index file        
  933.     if (generateHtmlIndex->GetValue() && !writeToSourceDir->GetValue()) {
  934.       vector <string>  fileList;
  935.       for (int i=0; i < listBox->GetCount(); i++){
  936.           fileList.push_back(string(listBox->GetString(i)));
  937.        }    
  938.        bool indexFileOK=generator->printIndexFile(fileList,  outPath);
  939.        if (!indexFileOK) {
  940.           wxMessageBox(wxString(i18n->getCParameter("e007")), 
  941.                        wxString(i18n->getCParameter("l025")), 
  942.                        wxICON_EXCLAMATION);
  943.        }    
  944.     }
  945.  
  946.    highlight::CodeGenerator::deleteInstance();
  947.    
  948.    formatMsg.Printf(i18n->getCParameter ("l023"), fileCount, stopWatch.Time());
  949.    progress->SetValue(0);
  950.    wxEndBusyCursor();
  951.    SetStatusText(formatMsg, 1);
  952.    if (!reformatFailures.IsEmpty()|| 
  953.        !inputFailures.IsEmpty() || 
  954.        !outputFailures.IsEmpty()) {
  955.        FailureDlg dlg(this, -1,wxString(i18n->getCParameter ("l034")),
  956.                       wxString(i18n->getCParameter ("e010")), reformatFailures,
  957.                       wxString(i18n->getCParameter ("e003")), inputFailures,
  958.                       wxString(i18n->getCParameter ("e004")), outputFailures );
  959.        dlg.ShowModal() ;
  960.    }
  961. }
  962.  
  963. highlight::WrapMode HighlightFrame::getWrappingStyle(){
  964.   if (wrapLinesCautious->GetValue()) return highlight::WRAP_SIMPLE;
  965.   return (wrapLines->GetValue())?highlight::WRAP_DEFAULT:highlight::WRAP_DISABLED; 
  966. }
  967.  
  968. string HighlightFrame::getFileType(const string& suffix)
  969. {
  970.   return (extensions.count(suffix)) ? extensions[suffix] : suffix ;
  971. }
  972.  
  973. string HighlightFrame::getFileSuffix(const string& fileName)
  974. {
  975.   unsigned int ptPos=fileName.rfind(".");
  976.   return (ptPos == string::npos) ? "" : fileName.substr(ptPos+1, 
  977.                                         fileName.length());
  978. }
  979.  
  980. string HighlightFrame::getOutFileSuffix(){
  981.   switch (outputFormat->GetSelection()) {
  982.     case 0: return ".html";
  983.     case 1: return ".xhtml";
  984.     case 4: return ".rtf";
  985.     case 5: return ".fo";    
  986.     case 6: return ".xml";    
  987.   }
  988.   return ".tex";
  989. }
  990.  
  991. bool DropFiles::OnDropFiles (wxCoord x, wxCoord y, const wxArrayString& filenames) {
  992.   for (size_t n = 0; n < filenames.Count(); n++) {
  993.     if (wxFileName(filenames[n]).IsDir()) {
  994.         wxMessageBox (_("Directories are not allowed!"),
  995.                       _("Error"), wxOK | wxICON_EXCLAMATION);
  996.         return FALSE;
  997.     }
  998.   }
  999.   m_frame->addInputFiles(filenames, "");
  1000.   return TRUE;
  1001. }
  1002.